package com.ygqh.baby.exception;

import com.foxinmy.weixin4j.util.StringUtil;
import com.ygqh.baby.ao.ExceptionMsg;

public class YgHttpException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */

	private String errorCode;

	private String errorMsg;

	public YgHttpException(String errorCode, String errorMsg) {
		this.errorCode = errorCode;
		this.errorMsg = errorMsg;
	}

	public YgHttpException(ExceptionMsg e) {
		this.errorCode = e.getCode();
		this.errorMsg = e.getMsg();
	}

	public YgHttpException(String errorMsg) {
		this.errorCode = "-1";
		this.errorMsg = errorMsg;
	}

	public YgHttpException(Throwable e) {
		super(e);
	}

	public YgHttpException(String message, Throwable cause) {
		super(message, cause);
	}

	public String getErrorCode() {
		return errorCode;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	@Override
	public String getMessage() {
		StringBuilder buf = new StringBuilder();
		if (StringUtil.isNotBlank(errorCode)) {
			buf.append(errorCode);
		}
		if (StringUtil.isNotBlank(errorMsg)) {
			buf.append(" ").append(errorMsg);
		}
		if (buf.length() == 0) {
			return super.getMessage();
		}
		return buf.toString();
	}

}
